package servlets;

import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.nio.file.attribute.AclEntry.Builder;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.xml.bind.ValidationException;

import business.BusinessDelegate;
import dto.MesaDTO;
import dto.PlatoDTO;
import dto.SucursalDTO;
import dto.itemComandaDTO;




/**
 * Servlet implementation class GenerarComandaServlet
 */

public class GenerarComandaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GenerarComandaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String action = request.getParameter("action");
		
		HttpSession session=request.getSession(true);
		
		if ("Agregar".equals(action))
         {
			System.out.println(request.getParameter("numeroMesa"));
             String id = request.getParameter("id");
             PlatoDTO p=new PlatoDTO();
             p.setId(Integer.parseInt(id));
             PlatoDTO plato;
			try {
				plato = BusinessDelegate.getInstance().getSistema().buscarPlatoDTO(p);
				itemComandaDTO item=new itemComandaDTO();
	            item.setPlato(plato);
	            request.getSession().setAttribute("item", item);
	            RequestDispatcher rd = request.getRequestDispatcher("GenerarComandaConCantidad.jsp");
				rd.forward(request, response);
			} catch (ValidationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            
           // response.sendRedirect("GenerarComandaConCantidad.jsp");
			
            
            
             
   
				
		
	}
	}

}
